[id].vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <template>
  2. <!-- 页面头部 -->
  3. <HomePageHead></HomePageHead>
  4. <!-- 导航栏 -->
  5. <HomePageNavigation1></HomePageNavigation1>
  6. <!-- 列表页广告一 -->
  7. <HomeTopTen :imgurl="adList[0]" v-if="adList[0]"></HomeTopTen>
  8. <!-- 面包屑导航 -->
  9. <div class="breadcrumb">
  10. <div class="inner">
  11. <span class="location">当前位置:</span>
  12. <el-breadcrumb :separator-icon="ArrowRight">
  13. <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
  14. <el-breadcrumb-item :to="{ path: `/newsList/${routLevelId}` }">{{ routLevelTitle }}</el-breadcrumb-item>
  15. <!-- <el-breadcrumb-item>文章详情</el-breadcrumb-item> -->
  16. <el-breadcrumb-item>{{ routeNewsTtitle }}</el-breadcrumb-item>
  17. </el-breadcrumb>
  18. </div>
  19. </div>
  20. <!-- 资讯列表 -->
  21. <div class="newsDetail">
  22. <div class="inner">
  23. <div class="innerLeft">
  24. <div class="LeftTop">
  25. <h1>{{ newsDetail.title }}</h1>
  26. <p>
  27. 来源: <span>{{ newsDetail.copyfrom }}</span>
  28. 作者: <span>{{ newsDetail.author }}</span>
  29. 发布时间: <span>{{ time }}</span>
  30. <!-- 浏览量: <span>{{ newsDetail.hits }}</span> -->
  31. </p>
  32. <img :src="newsDetail.imgurl" alt="">
  33. </div>
  34. <div class="leftBottom" v-html="newsDetail.content"></div>
  35. <!-- 免责声明: -->
  36. <div class="disclaimer" v-if="newsDetail.fromurl">
  37. <p>原文链接:{{ newsDetail.fromurl }}</p>
  38. <p>[免责声明]本文来源于网络转载,仅供学习交流使用,不构成商业目的。 版权归原作者所有,如涉及作品内容,版权和其他问题,请在30日与本网联系,我们将第一时间处理。</p>
  39. </div>
  40. </div>
  41. <div class="innerRight">
  42. <!-- 热点资讯1 -->
  43. <div class="hotList1">
  44. <DetailHotNews></DetailHotNews>
  45. </div>
  46. <!-- 热点资讯2 -->
  47. <div class="hotList2">
  48. <DetailHotNews2></DetailHotNews2>
  49. </div>
  50. </div>
  51. </div>
  52. </div>
  53. <!-- 页面底部 -->
  54. <HomeFoot1></HomeFoot1>
  55. </template>
  56. <script setup>
  57. import { onMounted } from 'vue'
  58. import { ElBreadcrumb, ElBreadcrumbItem } from 'element-plus'
  59. import { ArrowRight } from '@element-plus/icons-vue'
  60. const nuxtApp = useNuxtApp();
  61. const axios = nuxtApp.$axios;
  62. //获得跳转过来的id
  63. const route = useRoute();
  64. const articleId = route.params.id; //获得该页面的id
  65. const listid = route.query.listId; //获得该页面的id
  66. const name = route.query.listName; //获得该页面的id
  67. // 定义响应式数据
  68. const seoData = ref({
  69. title: '三农资讯网',
  70. description: '默认描述',
  71. keywords: '默认关键词',
  72. image: 'https://example.com/default-image.jpg'
  73. });
  74. // 在 onMounted 钩子中获取数据
  75. onMounted(async () => {
  76. try {
  77. const response = await axios.get(`/web/selectWebsiteArticleInfo?articleid=${articleId}`);
  78. const data = response.data; // 假设接口返回的数据在 data 字段中
  79. // 更新 seoData
  80. seoData.value = {
  81. title: data.title,
  82. description: data.seo_description,
  83. keywords: data.keyword,
  84. image: data.introduce
  85. };
  86. } catch (error) {
  87. console.error('获取 SEO 数据失败:', error);
  88. // 设置默认值
  89. seoData.value = {
  90. title: '三农资讯网',
  91. description: '默认描述',
  92. keywords: '默认关键词',
  93. image: 'https://example.com/default-image.jpg'
  94. };
  95. }
  96. });
  97. // 监听 seoData 的变化,动态设置 SEO 字段
  98. watch(seoData, (newVal) => {
  99. if (newVal.title) { // 确保 title 有值
  100. useSeoMeta({
  101. title: newVal.title, // 使用动态值
  102. description: newVal.description,
  103. ogTitle: newVal.title,
  104. ogDescription: newVal.description,
  105. ogImage: newVal.image,
  106. twitterTitle: newVal.title,
  107. twitterDescription: newVal.description,
  108. twitterImage: newVal.image,
  109. keywords: newVal.keywords
  110. });
  111. }
  112. }, { immediate: true });
  113. const newsDetail = ref({})
  114. const routeNewsTtitle = ref("");
  115. //发布日期
  116. const time = ref("");
  117. //路径
  118. const routLevelTitle = ref("");
  119. const routLevelId = ref("");
  120. //获取详情
  121. const getNewsInfo = async () => {
  122. const response = await axios.get(`/web/selectWebsiteArticleInfo?articleid=${articleId}`);
  123. newsDetail.value = response.data;
  124. routLevelTitle.value = newsDetail.value.cat_name
  125. console.log(123145)
  126. routLevelId.value = newsDetail.value.category_id
  127. time.value = newsDetail.value.updated_at.split(' ')[0]
  128. if (newsDetail.value.title.length >= 30) {
  129. routeNewsTtitle.value = newsDetail.value.title.substr(0, 30) + "...";
  130. } else {
  131. routeNewsTtitle.value = newsDetail.value.title
  132. }
  133. }
  134. function getDays(time) {
  135. const date = new Date(time);
  136. const year = date.getFullYear();
  137. const month = date.getMonth() + 1;
  138. const day = date.getDate();
  139. return `${month}-${day}`;
  140. }
  141. //获得广告
  142. const adList = ref("");
  143. const aa='DETAIL'
  144. const getadList = async () => {
  145. try {
  146. const response = await axios.get(`/web/getWebsiteAdvertisement?ad_tag=${aa}`);
  147. adList.value = response.data;
  148. } catch (error) {
  149. console.error(error);
  150. }
  151. }
  152. onMounted(() => {
  153. getNewsInfo()
  154. getadList()
  155. })
  156. </script>
  157. <style lang="less" scoped>
  158. //导航条
  159. .breadcrumb {
  160. width: 100%;
  161. height: 22px;
  162. margin-bottom: 30px;
  163. font-family: Microsoft YaHei, Microsoft YaHei;
  164. font-weight: 400;
  165. font-size: 20px;
  166. color: #666666;
  167. line-height: 23px;
  168. text-align: left;
  169. font-style: normal;
  170. text-transform: none;
  171. .el-breadcrumb::v-deep {
  172. display: inline-block;
  173. vertical-align: -4px;
  174. }
  175. /deep/.el-breadcrumb__inner a,
  176. /deep/.el-breadcrumb__inner.is-link {
  177. color: #666666;
  178. font-weight: 400;
  179. text-decoration: none;
  180. transition: var(--el-transition-color);
  181. }
  182. span {
  183. font-family: Microsoft YaHei, Microsoft YaHei;
  184. font-weight: 400;
  185. font-size: 20px;
  186. color: #666666;
  187. line-height: 23px;
  188. text-align: left;
  189. font-style: normal;
  190. text-transform: none;
  191. }
  192. span:hover {
  193. color: #666666;
  194. }
  195. .location {
  196. margin-right: 20px;
  197. width: 100px;
  198. height: 22px;
  199. font-family: Microsoft YaHei, Microsoft YaHei;
  200. font-weight: 400;
  201. font-size: 20px;
  202. color: #666666;
  203. line-height: 23px;
  204. text-align: left;
  205. font-style: normal;
  206. text-transform: none;
  207. }
  208. }
  209. // 资讯列表
  210. .newsDetail {
  211. width: 100%;
  212. //height: 1400px;
  213. margin-bottom: 70px;
  214. .inner {
  215. width: 1200px;
  216. //height: 1400px;
  217. overflow: hidden;
  218. font-size: 16px;
  219. .innerLeft {
  220. // height: 1400px;
  221. border-top: 1px solid #139602;
  222. .LeftTop {
  223. height: 522px;
  224. margin-top: 50px;
  225. >h1 {
  226. line-height: 40px;
  227. margin-bottom: 30px;
  228. font-family: Microsoft YaHei, Microsoft YaHei;
  229. font-weight: bold;
  230. font-size: 30px;
  231. color: #333333;
  232. }
  233. >p {
  234. height: 18px;
  235. line-height: 18px;
  236. font-family: Microsoft YaHei, Microsoft YaHei;
  237. font-weight: 400;
  238. font-size: 14px;
  239. color: #999999;
  240. span {
  241. margin-right: 40px;
  242. }
  243. }
  244. >img {
  245. width: 680px;
  246. height: 382px;
  247. padding: 50px 0px 60px 55px;
  248. }
  249. }
  250. .leftBottom {
  251. width: 790px;
  252. // height: 754px;
  253. margin-top: 76px;
  254. font-size: 20px;
  255. line-height: 38px;
  256. margin-bottom: 30px;
  257. ul>li img{
  258. width: 790px;
  259. height: 382px;
  260. }
  261. img{
  262. width: 790px;
  263. height: 382px;
  264. }
  265. p.tinymce-material {
  266. img {
  267. width: 790px;
  268. }
  269. }
  270. >h3,
  271. >p {
  272. text-indent: 2em;
  273. width: 790px;
  274. font-family: Microsoft YaHei, Microsoft YaHei;
  275. font-size: 20px;
  276. color: #333333;
  277. line-height: 38px;
  278. padding-bottom: 30px;
  279. img {
  280. width: 790px;
  281. }
  282. }
  283. >h3 {
  284. font-weight: 600px;
  285. }
  286. >p {
  287. font-weight: 400;
  288. }
  289. }
  290. .disclaimer {
  291. width: 790px;
  292. overflow: hidden;
  293. border-top: 1px solid #e6e6e6;
  294. padding: 30px 0px;
  295. color: #999999;
  296. font-size: 17px;
  297. p {
  298. width: 790px;
  299. line-height: 30px;
  300. }
  301. }
  302. }
  303. .innerRight {
  304. width: 381px;
  305. // height: 605px;
  306. overflow: hidden;
  307. border-top: 1px solid #139602;
  308. .hotList1 {
  309. margin-bottom: 50px;
  310. }
  311. }
  312. }
  313. }
  314. .leftBottom::v-deep p img,
  315. .leftBottom::v-deep img,
  316. .leftBottom::v-deep video {
  317. max-width: 700px;
  318. }
  319. .leftBottom::v-deep h1,
  320. .leftBottom::v-deep h2,
  321. .leftBottom::v-deep h3,
  322. .leftBottom::v-deep h4,
  323. .leftBottom::v-deep h5,
  324. .leftBottom::v-deep h6 {
  325. font-size: 20px;
  326. font-weight: 500;
  327. }
  328. </style>